package mylab.commons.web.config;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import mylab.commons.web.mvc.dto.BaseEntityDTO;
import mylab.commons.web.mvc.entity.BaseEntity;
import mylab.commons.web.mvc.impl.SuperControllerImpl;
import mylab.starters.generator.code.CodeTemplate;
import mylab.starters.generator.code.config.CodeGeneratorProperties;
import mylab.starters.mybatis.template.SuperMapper;
import mylab.starters.mybatis.template.SuperService;
import mylab.starters.mybatis.template.impl.SuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;


@Configuration
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@ConditionalOnBean(CodeTemplate.class)
public class CodeGeneratorAutoConfiguration {

    private final CodeGeneratorProperties properties;


    @PostConstruct
    private void init() {
        properties.setSuperEntityClass(BaseEntity.class.getName());
        properties.setSuperDtoClass(BaseEntityDTO.class.getName());
        properties.setSuperMapperClass(SuperMapper.class.getName());
        properties.setSuperServiceClass(SuperService.class.getName());
        properties.setSuperServiceImplClass(SuperServiceImpl.class.getName());
        properties.setSuperControllerClass(SuperControllerImpl.class.getName());
    }

}
